package com.studio701.carguard.controller;



import com.studio701.carguard.pojo.HelpPlan;
import com.studio701.carguard.pojo.RespBean;
import com.studio701.carguard.service.IHelpPlanService;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xjc
 * @since 2022-03-16
 */
@RestController
@RequestMapping("/help-plan")
public class HelpPlanController {

    @Autowired
    IHelpPlanService iHelpPlanService;

    /**
     * 这里应该有个入参，为用户的经纬度，查找附近多大范围内的helpqingq
     * 这里为了方便直接返回
     * @return
     */
    @GetMapping
    public List<HelpPlan> getNearbyHelp(){
        List<HelpPlan> helpPlans= iHelpPlanService.list();
        return helpPlans;
    }

    @ApiOperation("添加求助信息")
    @PostMapping("/")
    public boolean insertHelpPlan(@RequestBody HelpPlan helpPlan){
        return iHelpPlanService.save(helpPlan);
    }

    @ApiOperation("修改求助信息")
    @PutMapping("/")
    RespBean updateHelpPlan(@RequestBody HelpPlan helpPlan){
        if (iHelpPlanService.updateHelpPlanByUserId(helpPlan)){
            return RespBean.success("更新成功");
        }else {
            return RespBean.error("更新失败");
        }
    }

    @ApiOperation("删除求助信息")
    @DeleteMapping("/")
    RespBean deleteHelpPlan(Integer id){
        if (iHelpPlanService.removeByUserId(id)){
            return RespBean.success("删除成功");
        }else {
            return RespBean.error("删除失败");
        }
    }

}
